package com.bosssoft.service.impl;

import com.bosssoft.entity.dto.FibUserRoleDTO;
import com.bosssoft.enums.CopyPropertityEnum;
import com.bosssoft.exception.DaoException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.mapper.FibUserRoleMapper;
import com.bosssoft.entity.po.FibUserRolePO;
import com.bosssoft.service.FibUserRoleService;
/**
 * @author Li kexi
 * Created on 2021/8/16.14:32
 */
@Slf4j
@Service
public class FibUserRoleServiceImpl extends ServiceImpl<FibUserRoleMapper, FibUserRolePO> implements FibUserRoleService{

    @Override
    public Long getRoleByUserId(Long userId) {
        return this.baseMapper.getRoleByUserId(userId);
    }

    @Override
    public boolean addUserRole(FibUserRoleDTO userRoleDTO) {
        try {
            FibUserRolePO userRolePO = new FibUserRolePO();
            BeanUtils.copyProperties(userRoleDTO, userRolePO);
            return this.baseMapper.insert(userRolePO) > 0;
        } catch (DaoException e) {
            log.info("addUserRole出错");
            throw DaoException.error().setCodeAndMessage(CopyPropertityEnum.RESOURCE_NULL_ERROR);
        }
    }

    @Override
    public boolean modifyUserRole(FibUserRoleDTO userRoleDTO) {
        try {
            FibUserRolePO userRolePO = new FibUserRolePO();
            BeanUtils.copyProperties(userRoleDTO, userRolePO);
            return this.baseMapper.updateById(userRolePO) > 0;
        } catch (DaoException e) {
            log.info("modifyUserRole出错");
            throw DaoException.error().setCodeAndMessage(CopyPropertityEnum.RESOURCE_NULL_ERROR);
        }
    }

    @Override
    public boolean banUserRoleById(Long id, Integer status) {
        return this.baseMapper.banUserRoleById(id, status) > 0;
    }

    @Override
    public boolean deleteUserRoleById(Long id) {
        return this.baseMapper.deleteById(id) > 0;
    }

    @Override
    public int updateBatch(List<FibUserRolePO> list) {
        return baseMapper.updateBatch(list);
    }
    @Override
    public int updateBatchSelective(List<FibUserRolePO> list) {
        return baseMapper.updateBatchSelective(list);
    }
    @Override
    public int batchInsert(List<FibUserRolePO> list) {
        return baseMapper.batchInsert(list);
    }
    @Override
    public int insertOrUpdate(FibUserRolePO record) {
        return baseMapper.insertOrUpdate(record);
    }
    @Override
    public int insertOrUpdateSelective(FibUserRolePO record) {
        return baseMapper.insertOrUpdateSelective(record);
    }
}
